package com.nbjtjc.safe.api.emg;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.emg.EmgPlanPublicMapper;
import com.nbjtjc.safe.mapper.emg.EmgPlanPublicWriteTargetMapper;
import com.nbjtjc.safe.model.emg.EmgPlanPublic;
import com.nbjtjc.safe.model.emg.EmgPlanPublicWriteTarget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther guqianbin
 * @date 2018/5/18 11:11
 * 发布应急的对象
 **/
@RestController
@RequestMapping("/planPublicTarget")
@CrossOrigin("*")
public class EmgPlanPublicWriteTargetController {
    @Autowired
    private EmgPlanPublicWriteTargetMapper emgPlanPublicWriteTargetMapper;

    @Autowired
    private EmgPlanPublicMapper emgPlanPublicMapper;
    @GetMapping("/findByPlanPublicId/{planPublicId}")
    public Result findByPlanPublicId(@PathVariable("planPublicId") int planPublicId){
        Result result=new Result();
        EmgPlanPublic emgPlanPublic=emgPlanPublicMapper.selectByPrimaryKey(planPublicId);
        if(ObjectUtil.isNull(emgPlanPublic)){
            result.setFalse("没有该应急响应");
            return result;
        }
        List<EmgPlanPublicWriteTarget> writeTargets=emgPlanPublicWriteTargetMapper
                .findByPlanPublicId(emgPlanPublic.getStartPlanId());
        result.setData(CollectionUtil.isEmpty(writeTargets)?new ArrayList<>():writeTargets);
        return result;
    }

}
